package com.lvmama.pangolin.HBaseOper;

import com.lvmama.pangolin.common.DateUtil;
import com.lvmama.pangolin.common.RowkeyGenerator;
import com.lvmama.pangolin.entity.tc.*;
import com.lvmama.pangolin.hbaseutil.HBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class TCHBEntityOperation {
	/**  
	* @Title：HBEntityOperation.java
	* @Author:zhoutianqi
	* @Description:
	* @Date：2017年3月7日下午3:52:00  
	*/
	@Autowired
	private HBaseUtils hBaseUtil;
	public boolean saveTCTicketProduct(Ticket_Commodity item,String rowkey,String tableName,String family,TCProductItem param){
		Map<String,String> map = new HashMap<String,String>();
		map.put("detail_id", item.getDetail_id());
		map.put("company_code", item.getCompany_code());
		map.put("platform_code", item.getPlatform_code());
		map.put("city_code", item.getCity_code());
		map.put("scenery_name", item.getScenery_name());
		map.put("scenery_addr", item.getScenery_addr());
		map.put("product_id", item.getProduct_id());
		map.put("detail_url", item.getDetail_url());
		map.put("lowest_price", item.getLowest_price());
		map.put("score", item.getScore());
		map.put("image_num", item.getImage_num());
		map.put("introduction", item.getIntroduction());
		map.put("sale_count", item.getSale_count());
		map.put("score_tag", item.getScore_tag());
		map.put("star_level", item.getStar_level());
		map.put("create_time", DateUtil.yyyyMMdd_NOT_.format(item.getCreate_time()));
		map.put("update_time", DateUtil.yyyyMMdd_NOT_.format(item.getUpdate_time()));
		map.put("task_id", item.getTask_id());
		map.put("task_date", DateUtil.yyyyMMdd_NOT_.format(item.getTask_date()));
		map.put("rsrv_str1", item.getRsrv_str1());
		map.put("rsrv_str2", item.getRsrv_str2());
		map.put("rsrv_str3", item.getRsrv_str3());
		map.put("snapshot_addr", item.getSnapshot_addr());
		map.put("comm_type_num", String.valueOf(param.getComm_type_num()));
		map.put("commodity_num", String.valueOf(param.getCommodity_num()));
		map.put("comm_preferential_num", String.valueOf(param.getComm_preferential_num()));
		map.put("comm_package_num", String.valueOf(param.getComm_package_num()));
		return hBaseUtil.save(map, tableName, family, rowkey);
	}
	public boolean saveTCTicketProduct(TCProductItem item,String tableName,String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("priceGrade", item.getPriceGrade());
		map.put("refundCondGrade", item.getRefundCondGrade());
		map.put("preferentialGrade", item.getPreferentialGrade());
		map.put("booktimeGrade", item.getBooktimeGrade());
		map.put("efficientGrade", item.getEfficientGrade());
		map.put("product_grade", item.getProduct_grade());
		return hBaseUtil.save(map, tableName, family, item.getId());
	}
	
	public boolean saveTCTicketCommodity(TCommodityItem item,String tableName,String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("priceGrade", String.valueOf(item.getPriceGrade()));
		map.put("refundCondGrade", String.valueOf(item.getRefundCondGrade()));
		map.put("preferentialGrade", String.valueOf(item.getPreferentialGrade()));
		map.put("booktimeGrade", String.valueOf(item.getBooktimeGrade()));
		map.put("efficientGrade", String.valueOf(item.getEfficientGrade()));
		map.put("commodityGrade", item.getCommodity_grade());
		return hBaseUtil.save(map, tableName, family, item.getId());
	}
	public boolean saveTCTicketCommodity(TCTicket_CommodityDetail item,String rowkey,String tableName,String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("detail_id", item.getDetail_id());
		map.put("commodity_type", item.getCommodity_type());
		map.put("commodity_id", item.getCommodity_id());
		map.put("commodity_name", item.getCommodity_name());
		map.put("commodity_url", item.getCommodity_url());
		map.put("product_id", item.getProduct_id());
		map.put("sale_cond", item.getSale_cond());
		map.put("refund_cond", item.getRefund_cond());
		map.put("rack_rate", item.getRack_rate());
		map.put("sale_price", item.getSale_price());
		map.put("preferential", item.getPreferential());
		map.put("price_list_id", item.getPrice_list_id());
		map.put("create_time", DateUtil.yyyyMMdd_NOT_.format(item.getCreate_time()));
		map.put("update_time", DateUtil.yyyyMMdd_NOT_.format(item.getUpdate_time()));
		map.put("task_id", item.getTask_id());
		map.put("task_date", DateUtil.yyyyMMdd_NOT_.format(item.getTask_date()));
		map.put("city_code", item.getCity_code());
		map.put("efficient_time", item.getEfficient_time());
		return hBaseUtil.save(map, tableName, family, rowkey);
	}
	public boolean saveTCTicketCommoPriceByList(List<TCTicketCommodityPrice> list,String commodityID,String tableName,String family,String productId){
		for(TCTicketCommodityPrice item:list){
			String rowKey = RowkeyGenerator.generateCommodityRowkey(commodityID, item.getSale_date(), productId);
			Map<String,String> map = new HashMap<String,String>();
			map.put("task_id", item.getTask_id());
			map.put("grab_time", DateUtil.yyyyMMdd_NOT_.format(item.getGrab_time()));
			map.put("sale_date", DateUtil.yyyyMMdd_NOT_.format(item.getSale_date()));
			map.put("sale_price", item.getSale_price());
			hBaseUtil.save(map, tableName, family, rowKey);
		}
		return true;
	}
	public boolean saveTCTicketCommoPrice(String taskId,Date create_time,String price,String commodityID,String tableName,String family,String productId){
		String rowKey = RowkeyGenerator.generateCommodityRowkey(commodityID, create_time, productId);
		Map<String,String> map = new HashMap<String,String>();
		map.put("task_id", taskId);
		map.put("grab_time", DateUtil.yyyyMMdd_NOT_.format(create_time));
		map.put("sale_date", DateUtil.yyyyMMdd_NOT_.format(create_time));
		map.put("sale_price", price);
		hBaseUtil.save(map, tableName, family, rowKey);
		return true;
	}
}
